package com.htu.courseService.exam.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.htu.courseService.common.vo.R;
import com.htu.courseService.exam.service.ExamService;
import com.htu.courseService.exam.vo.AnswerDto;
import com.htu.courseService.exam.vo.ExamDto;
import com.htu.courseService.exam.vo.ExamInfoDto;
import com.htu.courseService.exam.vo.ExamQuery;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/exam")
@RequiredArgsConstructor
@Slf4j
public class ExamController {
    private final ExamService examService;

    /**
     * 提交一个测试问卷
     * @param examDto
     * @return
     */
    @PostMapping("/submit")
    public R<?> submit(@RequestBody ExamDto examDto){
        examService.submitExam(examDto);
        return R.success();
    }

    @PostMapping("/page")
    public R<IPage<ExamInfoDto>> page(@RequestBody ExamQuery examQuery){
        IPage<ExamInfoDto> examInfoDtoList = examService.pageInfo(examQuery);
        return R.success(examInfoDtoList);
    }

    /**
     * 根据问卷id获取问卷详情
     * @param examId
     * @return
     */
    @GetMapping("/detail")
    public R<ExamDto> getExamDetail(Integer examId){
        ExamDto examDto = examService.getExamDetail(examId);
        return R.success(examDto);
    }

    /**
     * 查找我的考试测验
     * @param examQuery
     * @return
     */
    @PostMapping("/myPage")
    public R<IPage<ExamInfoDto>> myPage(@RequestBody ExamQuery examQuery){
        IPage<ExamInfoDto> examInfoDtoList = examService.getMyPageInfo(examQuery);
        return R.success(examInfoDtoList);
    }

    /**
     * 根据我的问卷id获取问卷详情
     * @param examId
     * @return
     */
    @GetMapping("/myDetail")
    public R<ExamDto> getMyExamDetail(Integer examId){
        ExamDto examDto = examService.getMyExamDetail(examId);
        return R.success(examDto);
    }

    /**
     * 提交考试测验
     * @param answerDto
     * @return
     */
    @PostMapping("/submitExam")
    public R<?> submitExam(@RequestBody AnswerDto answerDto){
        examService.submitExamDetail(answerDto);
        return R.success();
    }
}
